package com.shanghaionstar.carmanage.adapter;

import android.content.Context;
import android.text.TextUtils;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import com.onstar.cn.framework.annotation.FindViewById;
import com.onstar.cn.framework.base.CommonAdapter;
import com.onstar.cn.framework.base.CommonViewHolder;
import com.shanghaionstar.R;
import com.shanghaionstar.carmanage.model.FlowItem;

import java.util.List;

public class OnstarFlowCommonAdapter extends CommonAdapter<FlowItem> {

	private int clickPosition = -1;

	public int getClickPosition() {
		return clickPosition;
	}

	public void setClickPosition(int clickPosition) {
		this.clickPosition = clickPosition;
	}

	public OnstarFlowCommonAdapter(Context context, List<FlowItem> datas) {
		super(datas,context);
	}

	@Override
	public void getView(int position, CommonViewHolder viewHolder) {
		ViewHolder holder = (ViewHolder)viewHolder;
		holder.bindData(datas.get(position),position);
	}

	@Override
	public View getView(int position, View convertView, ViewGroup parent) {
		return super.getView(position, convertView, parent);
	}

	@Override
	public int layoutId() {
		return R.layout.onstar_data_calculator_item;
	}

	class ViewHolder extends CommonViewHolder{
		@FindViewById
		TextView title_tv,per_flow_tv,pre_day_tv,pre_value_tv;
		@FindViewById
		View flow_item_rl;
		public void bindData(FlowItem t,int pos){
			title_tv.setText(t.title);
			per_flow_tv.setText(t.perHour);
			pre_day_tv.setText(t.perDay);

			if(!TextUtils.isEmpty(pre_value_tv.getText()))
				pre_value_tv.setText(pre_value_tv.getText().toString());
			else
				pre_value_tv.setText("0");

			if(pos == 8){
				pre_value_tv.setText("");
				pre_day_tv.setText("");
			}

			if (getClickPosition() == pos) {
				flow_item_rl.setBackgroundColor(context.getResources().getColor(R.color.font_flow));
				title_tv.setTextColor(context.getResources().getColor(R.color.white));
				per_flow_tv.setTextColor(context.getResources().getColor(R.color.white));
				pre_day_tv.setTextColor(context.getResources().getColor(R.color.white));
				pre_value_tv.setTextColor(context.getResources().getColor(R.color.white));
				pre_value_tv.setTextSize(22);
			} else {
				flow_item_rl.setBackgroundResource(R.drawable.onstar_item_nor_bg);
				title_tv.setTextColor(context.getResources().getColor(R.color.profile_font_color));
				per_flow_tv.setTextColor(context.getResources().getColor(R.color.profile_tr_font_color));
				pre_day_tv.setTextColor(context.getResources().getColor(R.color.profile_tr_font_color));
				pre_value_tv.setTextColor(context.getResources().getColor(R.color.profile_tr_font_color));
				pre_value_tv.setTextSize(12);
			}
		}
	}

	@Override
	public CommonViewHolder getViewHolder() {
		return new ViewHolder();
	}
}
